package com.aaa.utils;

import cn.hutool.core.date.DateUtil;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;
import lombok.extern.slf4j.Slf4j;
import java.io.FileInputStream;
import java.util.Date;
import java.util.UUID;

/**
 * @author : luoBo
 */
@Slf4j
public class SubOutStreamUtil {

    public static void main(String[] args) throws Exception{

        Date date = new Date();
        String dateStr = DateUtil.formatDate(date);
        dateStr = dateStr.replace("-","/")+"/";
        String smbPath = "smb://10.10.80.200/share/nationalReport/dev/"+dateStr;
        SmbFile smbFile = new SmbFile(smbPath);
        if (!smbFile.exists()) {
            log.error("smb文件不存在");
            smbFile.mkdirs();
        }
        smbPath = smbPath + UUID.randomUUID() + ".xls";
        FileInputStream fileInputStream = new FileInputStream("D:/templates/ebefdf77-a85c-483d-a6a7-74f7d8e0bb1f.xls");
        byte[] bytes = new byte[1024];
        SmbFileOutputStream smbFileOutputStream = new SmbFileOutputStream(smbPath);
        while (fileInputStream.read(bytes) != -1){
                smbFileOutputStream.write(bytes);
        }
        smbFileOutputStream.close();
        fileInputStream.close();

    }
}
